import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
import numpy as np

plt.figure(figsize=(12, 12))

n_samples = 30
random_state = 50

x, y = make_blobs(n_samples=n_samples, cluster_std=[1,2,1], random_state=random_state)

plt.subplot(221)
plt.scatter(x[:,0],x[:,1], c=y)
plt.title("original")

y_pred = KMeans(n_clusters=3, init='random', n_init=1).fit_predict(x)
plt.subplot(222)
plt.scatter(x[:,0],x[:,1], c=y_pred)
plt.title("Pred1")

y_pred = KMeans(n_clusters=3, init='random', n_init=1).fit_predict(x)
plt.subplot(223)
plt.scatter(x[:,0],x[:,1], c=y_pred)
plt.title("Pred1")

y_pred = KMeans(n_clusters=3, init='random', n_init=1).fit_predict(x)
plt.subplot(224)
plt.scatter(x[:,0],x[:,1], c=y_pred)
plt.title("Pred1")


plt.savefig('cluster_random.png')